const Router = require('koa-router')

const { verifyAuth, verifyPermission } = require('../middleware/auth.middleware')
const { 
  publicMoment, 
  detail, 
  list, 
  updateMoment, 
  deleteMoment, 
  addLabel,
  fileInfo
} = require('../controller/moment.controller')
const { verifyLabelExists } = require('../middleware/label.middleware')
const momentRouter = new Router({ prefix: '/moment' })

// 发表动态
momentRouter.post('/', verifyAuth, publicMoment)

// 根据id查询动态
momentRouter.get('/:momentId', detail)

// 获取所有动态, 所有人都可以看，不需要验证权限
momentRouter.get('/', list)

// 根据id修改动态，需要登录，并且只能修改自己的动态
momentRouter.patch('/:momentId', verifyAuth, verifyPermission('moment'), updateMoment)

// 删除动态
momentRouter.delete('/:momentId', verifyAuth, verifyPermission('moment'), deleteMoment)

// 给动态添加标签
momentRouter.post('/:momentId/labels', verifyAuth, verifyPermission('moment'), verifyLabelExists, addLabel)

// 通过图片地址直接访问图片
momentRouter.get('/images/:filename', fileInfo)

module.exports = momentRouter
